/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <winsock2.h>

//--------------------------------------------------------------------
// RFC 2460
struct IP6HeaderPG{
	DWORD VTF;				// !!! Version + Trafic Class + Flow Label
	WORD PayloadLen;
	BYTE NextHeader;
	BYTE HopLimit;
	BYTE Source[16];
	BYTE Destination[16];
};
__inline BYTE IPv6HdrVersion(DWORD dataIn)
{
	return (BYTE)((ntohl(dataIn)>>28) & 0x0000000F);
}
__inline BYTE IPv6HdrTraficClass(DWORD dataIn)
{
	return (BYTE)((ntohl(dataIn)>>20) & 0x000000FF);
}
__inline DWORD IPv6HdrFlowLabel(DWORD dataIn)
{
	return ntohl(dataIn) & 0x000FFFFF;
}
//--------------------------------------------------------------------
// RFC 2460
struct HopByHopHeaderPG{
	BYTE NextHeader;
	BYTE HdrExtLen;
	// TLV Options
};
struct HopByHopHeaderRouterAlertPG{
	BYTE NextHeader;
	BYTE HdrExtLen;
	BYTE Data[6];
};

struct RoutingHeaderPG
{
	BYTE NextHeader;
	BYTE HdrExtLen;
	BYTE RoutingType;
	BYTE SegmentsLeft;
	// TLV Options
};

struct FragmentHeaderPG
{
	BYTE  NextHeader;
	BYTE  Reserved;
	WORD  FragOffsetRM;
	DWORD Id;
};

struct DestOptHeaderPG{
	BYTE NextHeader;
	BYTE HdrExtLen;
	// TLV Options
};

// RFC 4302
struct AuthHeaderPG{
	BYTE  NextHeader;
	BYTE  PayloadLen;
	WORD  Reserved;
	DWORD SPI;		// Security Parameter Index
	DWORD SNF;		// Sequence Number Field
	// DWORD[] ICV;
};

// RFC 4303
struct ESPHeaderPG{
	// nu este conform cu celelalte ?
};

//--------------------------------------------------------------------
// RFC 2460
struct IPv6PseudoHeader
{
	BYTE  Source[16];
	BYTE  Destination[16];
	DWORD PacketLength;
	BYTE  Zero[3];
	BYTE  NextHeader;
};

//--------------------------------------------------------------------
// RFC 2463
struct ICMP6HeaderPG{
	BYTE Type;
	BYTE Code;
	WORD Checksum;		// computed with pseudoheader, see RFC2463:2.3 Message Checksum Calculation
	// BYTE[] MsgBody;
};

struct ICMP6EchoPG{
	BYTE Type;		// 128 = Request, 129 = Reply
	BYTE Code;		// 0
	WORD Checksum;		// computed with pseudoheader, see RFC2463:2.3 Message Checksum Calculation
	WORD Id;
	WORD Seq;
	// BYTE[] Data;
};

struct ICMP6RouterPG{
	BYTE  Type;
	BYTE  Code;
	WORD  Checksum;
	DWORD Reserved;
	// BYTE[] Options;
};

struct ICMP6NeighborPG{
	BYTE  Type;
	BYTE  Code;
	WORD  Checksum;
	DWORD Reserved;		// reserved for NS, flags for NA
	BYTE  TargetAddr[16];
};
__inline bool ICMPv6NeighborIsRouter(DWORD dataIn)
{
	return (ntohl(dataIn) & 0x80000000) ? true : false;
}
__inline bool ICMPv6NeighborIsSolicited(DWORD dataIn)
{
	return (ntohl(dataIn) & 0x40000000) ? true : false;
}
__inline bool ICMPv6NeighborIsOverride(DWORD dataIn)
{
	return (ntohl(dataIn) & 0x20000000) ? true : false;
}

struct ICMP6MLD{
	BYTE Type;
	BYTE Code;
	WORD Checksum;
	WORD MaximumResponseDelay;
	WORD Reserved;
	BYTE McastAddr[16];
};

struct ICMP6ParameterProblem{
	BYTE  Type;
	BYTE  Code;
	WORD  Checksum;
	DWORD Pointer;
};

//--------------------------------------------------------------------

class PacketDefinitions6
{
public:
	PacketDefinitions6(void);
	~PacketDefinitions6(void);
};

//--------------------------------------------------------------------
